package biz

import (
	"context"

	v1 "kratosErrCode/api/helloworld/v1"

	"github.com/go-kratos/kratos/v2/log"
)

// Greeter is a Greeter model.
type Greeter struct {
	Hello string
}

// GreeterRepo is a Greater repo.
type GreeterRepo interface {
	Save(context.Context, *Greeter) (*Greeter, error)
}

// GreeterUsecase is a Greeter usecase.
type GreeterUsecase struct {
	repo GreeterRepo
	log  *log.Helper
}

// NewGreeterUsecase new a Greeter usecase.
func NewGreeterUsecase(repo GreeterRepo, logger log.Logger) *GreeterUsecase {
	return &GreeterUsecase{repo: repo, log: log.NewHelper(logger)}
}

func (uc *GreeterUsecase) CreateGreeter(ctx context.Context, req *v1.HelloRequest) (*v1.HelloReply, error) {
	reply := v1.HelloReply{}
	reply.Name = req.Name

	currDesc := v1.Desc{
		Gender: "male",
		Hobby:  []string{"football", "basketball"},
	}

	reply.Desc = &currDesc

	return &reply, nil
}

func (uc *GreeterUsecase) GetUser(ctx context.Context, req *v1.Empty) (*v1.Empty, error) {
	reply := &v1.Empty{}

	// Notice 返回错误
	if 1 == 1 {
		return nil, ErrUserInBlankList
	}

	return reply, nil
}
